home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 301-325 / 325 / dorevision / dorevision.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  5KB  |  254 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1990 by MXM
  4.  *
  5.  *    Name .....: DoRevision.c
  6.  *    Created ..: Saturday 27-Jan-90 19:18
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    27-Jan-90       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  #define REVISION 0
  15.  
  16. #include <libraries/dosextens.h>
  17. #include <exec/memory.h>
  18. #include <stdio.h>
  19.  
  20. #define TEMPNAME "T:Revision.temp"
  21.  
  22. extern struct FileLock    *Lock();
  23. extern void        *AllocMem();
  24.  
  25. LONG
  26. CmpStr(s,t)
  27. char *s,*t;
  28. {
  29.     register LONG i;
  30.  
  31.     for(i = 0 ; i < strlen(s) ; i++)
  32.         if(s[i] != t[i])
  33.             return(s[i] - t[i]);
  34.  
  35.     return(0);
  36. }
  37.  
  38. char *
  39. GetRealName(s,Protect)
  40. char *s;
  41. long *Protect;
  42. {
  43.     struct FileInfoBlock    *FileInfo;
  44.     struct FileLock        *FileLock;
  45.  
  46.     static char         FileName[108];
  47.  
  48.     if(!(FileLock = (struct FileLock *)Lock(s,ACCESS_READ)))
  49.         return(NULL);
  50.  
  51.     if(!(FileInfo = (struct FileInfoBlock *)AllocMem((long)sizeof(struct FileInfoBlock),MEMF_PUBLIC)))
  52.     {
  53.         UnLock(FileLock);
  54.         return(NULL);
  55.     }
  56.  
  57.     if(!Examine(FileLock,FileInfo))
  58.     {
  59.         FreeMem(FileInfo,(long)sizeof(struct FileInfoBlock));
  60.         UnLock(FileLock);
  61.         return(NULL);
  62.     }
  63.  
  64.     strcpy(FileName,FileInfo -> fib_FileName);
  65.  
  66.     *Protect = FileInfo -> fib_Protection;
  67.  
  68.     FreeMem(FileInfo,(long)sizeof(struct FileInfoBlock));
  69.     UnLock(FileLock);
  70.  
  71.     return(FileName);
  72. }
  73.  
  74. LONG
  75. Revise(Name,LogMessage)
  76. char *Name,*LogMessage;
  77. {
  78.     char *LineBuff,*FileName;
  79.     long InLine = 0,Revision = 0,SkipNext = FALSE,i,Protect;
  80.     FILE *Rev,*Temp;
  81.     char Year[10],Author[20],Day[20],Time[10],Company[40];
  82.     BOOL Create = TRUE;
  83.  
  84.     if(!LogMessage)
  85.         LogMessage = "- Empty log message -";
  86.  
  87.     if(getenv("DATE"))
  88.         strcpy(Year,getenv("DATE"));
  89.     else
  90.         strcpy(Year,"01-01-90");
  91.  
  92.     if(getenv("DAY"))
  93.         strcpy(Day,getenv("DAY"));
  94.  
  95.     if(getenv("TIME"))
  96.         strcpy(Time,getenv("TIME"));
  97.  
  98.     if(getenv("AUTHOR"))
  99.         strcpy(Author,getenv("AUTHOR"));
  100.     else
  101.         strcpy(Author,"- Unknown -");
  102.  
  103.     if(getenv("COMPANY"))
  104.         strcpy(Company,getenv("COMPANY"));
  105.     else
  106.         strcpy(Company,"???");
  107.  
  108.     if(!(LineBuff = (char *)AllocMem(256L,MEMF_PUBLIC | MEMF_CLEAR)))
  109.         return;
  110.  
  111.     if(!(FileName = GetRealName(Name,&Protect)))
  112.     {
  113.         FreeMem(LineBuff,256L);
  114.         return;
  115.     }
  116.  
  117.     if(!(Temp = fopen(TEMPNAME,"w")))
  118.     {
  119.         FreeMem(LineBuff,256L);
  120.         return;
  121.     }
  122.  
  123.     if(!(Rev = fopen(Name,"r")))
  124.     {
  125.         fclose(Temp);
  126.         FreeMem(LineBuff,256L);
  127.         return;
  128.     }
  129.  
  130.     if(!fgets(LineBuff,256,Rev))
  131.     {
  132.         fclose(Temp);
  133.         fclose(Rev);
  134.         FreeMem(LineBuff,256L);
  135.         return;
  136.     }
  137.  
  138.     fclose(Rev);
  139.  
  140.     if(!CmpStr("/* $Revision Header *",LineBuff))
  141.         Create = FALSE;
  142.  
  143.     if(Create)
  144.     {
  145.         fprintf(Temp,"/* $Revision Header *** Header built automatically - do not edit! ***********\n");
  146.         fprintf(Temp," *\n *\t(C) Copyright 19%s by %s\n *\n",Year + 7,Company);
  147.  
  148.         fprintf(Temp," *\tName .....: %s\n",FileName);
  149.         fprintf(Temp," *\tCreated ..: %s %s %s\n",Day,Year,Time);
  150.         fprintf(Temp," *\tRevision .: 0\n");
  151.         fprintf(Temp," *\n");
  152.  
  153.         fprintf(Temp," *\tDate            Author          Comment\n");
  154.         fprintf(Temp," *\t=========       ========        ====================\n");
  155.  
  156.         fprintf(Temp," *\t%s       %-15.15s %s\n",Year,Author,"Created this file!");
  157.  
  158.         fprintf(Temp," *\n");
  159.         fprintf(Temp," * $Revision Header ********************************************************/\n");
  160.         fprintf(Temp," #define REVISION 0\n\n");
  161.     }
  162.  
  163.     if(!(Rev = fopen(Name,"r")))
  164.     {
  165.         fclose(Temp);
  166.         FreeMem(LineBuff,256L);
  167.         return;
  168.     }
  169.  
  170.     for(;;)
  171.     {
  172.         if(!fgets(LineBuff,256,Rev))
  173.             break;
  174.  
  175.         if(InLine == 6 && !Create)
  176.         {
  177.             Revision = atoi(LineBuff + 15) + 1;
  178.             sprintf(LineBuff," *\tRevision .: %d\n",Revision);
  179.         }
  180.  
  181.         if(InLine == 10 && !Create)
  182.         {
  183.             char TempBuff[11];
  184.  
  185.             for(i = 0 ; i < 10 ; i++)
  186.                 TempBuff[i] = LineBuff[3 + i];
  187.  
  188.             TempBuff[9] = 0;
  189.  
  190.             if(!CmpStr(TempBuff,Year) && (Protect & FIBF_ARCHIVE))
  191.             {
  192.                 fclose(Rev);
  193.                 fclose(Temp);
  194.                 FreeMem(LineBuff,256L);
  195.                 DeleteFile(TEMPNAME);
  196.  
  197.                 return;
  198.             }
  199.  
  200.             fprintf(Temp," *\t%s       %-15.15s %s\n",Year,Author,LogMessage);
  201.         }
  202.  
  203.         if(SkipNext)
  204.         {
  205.             sprintf(LineBuff," #define REVISION %d\n",Revision);
  206.             SkipNext = FALSE;
  207.         }
  208.  
  209.         if(!CmpStr(" * $Revision Header *",LineBuff) && InLine)
  210.             SkipNext = TRUE;
  211.  
  212.         fwrite(LineBuff,strlen(LineBuff),1,Temp);
  213.         InLine++;
  214.     }
  215.  
  216.     fclose(Temp);
  217.     fclose(Rev);
  218.  
  219.     if(!(Temp = fopen(TEMPNAME,"r")))
  220.     {
  221.         FreeMem(LineBuff,256L);
  222.         return;
  223.     }
  224.  
  225.     if(!(Rev = fopen(Name,"w")))
  226.     {
  227.         fclose(Temp);
  228.         DeleteFile(TEMPNAME);
  229.  
  230.         FreeMem(LineBuff,256L);
  231.         return;
  232.     }
  233.  
  234.     while((InLine = fgetc(Temp)) != EOF)
  235.         fputc(InLine,Rev);
  236.  
  237.     fclose(Temp);
  238.     fclose(Rev);
  239.  
  240.     SetProtection(Name,Protect | FIBF_ARCHIVE);
  241.  
  242.     DeleteFile(TEMPNAME);
  243.  
  244.     FreeMem(LineBuff,256L);
  245. }
  246.  
  247. void
  248. main(argc,argv)
  249. int argc;
  250. char *argv[];
  251. {
  252.     Revise(argv[1],argv[2]);
  253. }
  254.